Skip to content

MDEV-37990: redundant Table map events in binlog#5121

Open
plampio wants to merge 1 commit into
10.11from
10.11-MDEV-37990
Open

MDEV-37990: redundant Table map events in binlog#5121
plampio wants to merge 1 commit into
10.11from
10.11-MDEV-37990

Conversation

@plampio
Copy link
Copy Markdown
Contributor

@plampio plampio commented May 25, 2026

This patch modifies how a Galera slave node writes Table map events to binary log. Now a Galera slave does not write duplicate Table Map events to binary log.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@plampio plampio self-assigned this May 25, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses MDEV-37990 by preventing redundant Table_map events in the binary log during Galera replication. It introduces a mechanism in the THD class to track mapped tables within a transaction. The review feedback identifies several areas for improvement: correcting MariaDB coding style and return types in sql/log.cc, fixing a regex bug in the test script that prevents correct transaction boundary detection, and suggesting the use of a more lightweight container than std::unordered_set in the core sql_class.h header to optimize performance and compilation times.

Comment thread sql/log.cc
Comment on lines +6491 to +6498
#ifdef WITH_WSREP
if (wsrep_thd_is_applying(this)
&& !wsrep_mark_table_mapped(table->s->table_map_id)) {
/* A table map event for this table is already recorded for this
transaction, skip writing the table map event. */
DBUG_RETURN(0);
}
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The indentation and brace placement in this block do not follow the MariaDB coding style. The block inside the if statement should be indented by 2 spaces relative to the if, and the opening brace { is typically placed on a new line. Additionally, for a function returning bool, false is more idiomatic than 0 to indicate success.

#ifdef WITH_WSREP
  if (wsrep_thd_is_applying(this) &&
      !wsrep_mark_table_mapped(table->s->table_map_id))
  {
    /* A table map event for this table is already recorded for this
       transaction, skip writing the table map event. */
    DBUG_RETURN(false);
  }
#endif
References
  1. MariaDB coding style: 2-space indentation, opening braces on a new line for blocks, and use 'false' for boolean success in functions returning bool. (link)

my (%per_txn, $xid, %out);
$xid = 0;
while (my $line = <$fh>) {
$xid++ if $line =~ /^(?:COMMIT|Xid =)/;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The regex /^(?:COMMIT|Xid =)/ is anchored to the start of the line, but Xid = in mysqlbinlog output is typically preceded by metadata and a tab. This will prevent the regex from correctly identifying transaction boundaries for XID events. Removing the ^ anchor will allow it to match correctly.

      $xid++ if $line =~ /COMMIT|Xid =/;

Comment thread sql/sql_class.h
#include "wsrep_client_state.h"
#include "wsrep_mutex.h"
#include "wsrep_condition_variable.h"
#include <unordered_set>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Including <unordered_set> in a core header like sql_class.h can increase compilation times. Additionally, std::unordered_set is relatively heavy for tracking a small number of tables. Consider using a more lightweight container like Prealloced_array or std::vector with linear search, which would be more efficient for the typical case and avoid unnecessary heap allocations.

This patch modifies how a Galera slave node writes Table map events to
binary log. Now a Galera slave does not write duplicate Table Map
events to binary log.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants